package ui.AdminUis;

import java.util.List;

import sun.security.util.DerInputStream;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Button;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Select;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;

import db.DatabaseDergiHelper;
import db.Databasehelper;
import domain.DergiDomain;

public class dergiSilUi extends CustomComponent {

	private static final long serialVersionUID = -6329525126686788382L;
	private DergiDomain dergi;
	
	public dergiSilUi() {
		initVerticallayout();
	}

	private void initVerticallayout() {
		final Select silinecekDergi = initselect();
		Panel  dergiSilPanel    = new Panel();
		FormLayout dergiSilForm = new FormLayout();
		Button onayButonu       = new Button("Dergiyi Sil",new Button.ClickListener() {
		DatabaseDergiHelper db  = new DatabaseDergiHelper();
			/**
			 * 
			 */
			private static final long serialVersionUID = -1299633275319858877L;

			public void buttonClick(ClickEvent event) {
				db.dergiSil(silinecekDergi.getValue().toString());
				getWindow().showNotification(silinecekDergi+" basari ile silindi");
			}
		});
		
		dergiSilForm.setWidth("400px");
		dergiSilForm.setHeight("200px");
		
		dergiSilForm.addComponent(silinecekDergi);
		dergiSilForm.addComponent(onayButonu);
		
		dergiSilPanel.setContent(dergiSilForm);
		setCompositionRoot(dergiSilPanel);
	}

	private Select initselect() {
		Select silinecekDergi = new Select("Silinecek Dergi");
		
		silinecekDergi.setNullSelectionAllowed(false);
		DatabaseDergiHelper db= new DatabaseDergiHelper();
		List<String> dergiler = db.dergilistesi();
		
		for (String dergi : dergiler) {
			silinecekDergi.addItem(dergi);
		}
		return silinecekDergi;
	}
}
